#include "stdafx.h"
#include "ckLandsatMetaData.h"
#include "ckMetaGroup.h"

namespace ck
{
	namespace data
	{
		LandsatMeta::LandsatMeta()
		{
		}


		LandsatMeta::~LandsatMeta()
		{
			MetaGroup* pGroup = NULL;
			std::vector<MetaGroup*>::iterator iter;
			for (iter = m_groups.begin(); iter != m_groups.end(); iter++)
			{
				pGroup = *iter;
				pGroup->Release();
			}
			m_groups.clear();

		}

		RESULTCODE LandsatMeta::AddGroup(MetaGroup* pGroup)
		{
			if (pGroup == NULL)
			{
				return RC_FAILURE;
			}

			m_groups.push_back(pGroup);

			return RC_SUCCESS;
		}

		MetaGroup* LandsatMeta::GetGroup(z_uint32 i)
		{
			if (i >= m_groups.size())
			{
				return NULL;
			}
			return m_groups[i];
		}

		z_uint32 LandsatMeta::GetCount()
		{
			return m_groups.size();
		}

		void LandsatMeta::SetName(const char* szName)
		{
			if (szName)
			{
				m_strName = szName;
			}
			else
			{
				m_strName.clear();
			}
		}

		const char*	LandsatMeta::GetName()
		{
			return m_strName.c_str();
		}

		MetaGroup* LandsatMeta::GetGroup(const char* szName)
		{
			if (szName == NULL)
			{
				return NULL;
			}

			std::vector<MetaGroup*>::iterator iter;
			for (iter = m_groups.begin(); iter != m_groups.end(); iter++)
			{
				if (strcmp(szName, (*iter)->GetName()) == 0)
				{
					return (*iter);
				}
			}
			return NULL;
		}

		void LandsatMeta::SetDatasetName(const char* szName)
		{
			if (szName)
			{
				m_strDatasetName = szName;
			}
			else
			{
				m_strDatasetName.clear();
			}
		}

		const char*	LandsatMeta::GetDatasetName()
		{
			return m_strDatasetName.c_str();
		}
	}
}


